package cn.akwangl.common.uoload.aliyun;

import com.aliyun.oss.OSSClient;
import com.aliyun.oss.model.PutObjectResult;
import com.aliyuncs.auth.sts.AssumeRoleResponse;
import org.springframework.stereotype.Component;

import java.io.InputStream;

@Component
public class ALiOSS {

    String endpoint = "oss-cn-beijing.aliyuncs.com";
    String bucketName = "akwangl";

    public boolean upLoad(AssumeRoleResponse response, InputStream inputStream) {
        // 创建OSSClient实例。
        OSSClient ossClient = new OSSClient(endpoint, response.getCredentials().getAccessKeyId(), response.getCredentials().getAccessKeySecret(), response.getCredentials().getSecurityToken());

        PutObjectResult putObjectResult = ossClient.putObject(bucketName, "123456.jpg", inputStream);
        System.out.println("putObjectResult => " + putObjectResult);
        return false;
    }

}
